import {Injectable} from '@angular/core';
import {BaseHttpService} from '../base-http.service';
import {Observable} from 'rxjs';
import {PageInfo, SearchCommonVO} from '../../types';

export interface MyGradesModel {
  userId: number;
  questionTestId: number;
  questionTestName: string;
  userName: string;
  countTest: number;
  maxScore: number;
  passFlag: boolean;
  lastTestTime: Date;
}

export interface WrongTopicModel {
  id: number;
  questionId: number;
  content: string;
  questionCount: number;
  createTime: Date;
}

export interface QueryTestUserParam {
  userId: number;
  questionTestId: number;
}

/*用户考试明细*/
export interface TestUserDetail extends QueryTestUserParam {
  id?: number;
  useTime: Date;
  startTime: Date;
  score: number;
  passFlag: boolean;
}

@Injectable({
  providedIn: 'root'
})
export class MyGradesService {

  constructor(public http: BaseHttpService) {
  }

  public getResults(params: SearchCommonVO<any>): Observable<PageInfo<MyGradesModel>> {
    return this.http.post('/my-question-test', params);
  }

  public getWrongTopic(params: SearchCommonVO<any>): Observable<PageInfo<WrongTopicModel>> {
    return this.http.post('/my-question-book', params);
  }

  public delWrongTopic(idArray: number[]): Observable<void> {
    return this.http.post('/del-question-book/', {ids: idArray}, {needSuccessInfo: true});
  }

  /*错题本id集合*/
  public getWrongTopicId(params: SearchCommonVO<any>): Observable<any[]> {
    return this.http.post('/my-question-book-ids', params);
  }

  /*用户考试明细接口*/
  public getUserTestDetail(param: QueryTestUserParam): Observable<TestUserDetail[]> {
    return this.http.get('/user-detail-question-test', param);
  }
}
